﻿
#pragma once

/// @addtogroup helpers_any
/// @{

namespace helpers {

	class Any
	{    
		typedef boost::any	Value;

	public:
		operator bool()
		{
			return !empty();
		}

		bool empty()
		{
			return _value.empty();
		}

	public:
		template <typename T>
		operator T()
		{
			return boost::any_cast<T>(_value);
		}

		template <typename T>
		operator T() const
		{
			return boost::any_cast<T>(_value);
		}

		template<typename T>
		T get()
		{
			return boost::any_cast<T>(_value);
		}

	public:
		template<typename ValueType>
		Any(const ValueType & value)
			: _value(value)
		{
		}
		
		Any()
			: _value()
		{
		}
		
		Any(const Any& other)
			: _value(other._value)
		{

		}

		~Any()
		{

		} 

	public: // modifiers

		Any & swap(Any& rhs)
		{
			_value.swap(rhs._value);
			return *this;
		}


		template<typename ValueType>
		Any & operator=(const ValueType & rhs)
		{
			Any(rhs).swap(*this);
			return *this;
		}

		Any& operator=(Any rhs)
		{
			rhs.swap(*this);
			return *this;
		}

	private:
		Value	_value;
	};

} // namespace helpers


/// @}

/// @addtogroup helpers
/// @{
///		@defgroup helpers_any Any
/// @}

/**
 * @addtogroup helpers_any
 * @{
 * @par 代码示例
 * @code
 * 
 * class CTest;
 * CTest test;
 * 
 * Any a = test;
 *
 * CTest test2 = static_cast<CTest>(a); // OK
 *
 * @endcode

 * @}
 */
